import type { RowType } from '#/views/system/role/role.data';

import { requestClient } from '#/api/request';

export namespace SysRoleTableApi {
  export type RowTypeFetchParams = RowType;
  export interface IdFetchParams {
    id: string;
  }
  export interface ListFetchParams {
    [key: string]: any;
  }
  export interface PageListFetchParams {
    [key: string]: any;
    pageNo: number;
    pageSize: number;
  }
  export interface RoleAuthParams {
    roleId: string;
    authIds: [];
  }
}

/**
 * 分页列表查询
 */
export async function roleQueryPageListApi(
  params: SysRoleTableApi.PageListFetchParams,
) {
  return requestClient.get('/sys/role/queryPageList', { params });
}

/**
 * 列表查询
 */
export async function roleQueryListApi(
  params: SysRoleTableApi.ListFetchParams,
) {
  return requestClient.get('/sys/role/queryList', { params });
}

/**
 * 通过ID查询
 * @param params
 */
export async function roleQueryByIdApi(params: SysRoleTableApi.IdFetchParams) {
  return requestClient.get('/sys/role/queryById', { params });
}

/**
 * 新增
 */
export async function roleAddApi(params: SysRoleTableApi.RowTypeFetchParams) {
  return requestClient.post('/sys/role/add', params);
}

/**
 * 编辑
 */
export async function roleEditApi(params: SysRoleTableApi.RowTypeFetchParams) {
  return requestClient.post('/sys/role/edit', params);
}

/**
 * 删除
 * @param id 主键
 */
export async function roleDelApi(id) {
  return requestClient.delete<boolean>(`/sys/role/delete/${id}`);
}

/**
 * 批量删除删除
 * @param ids 主键
 */
export async function roleDeleteBatchApi(ids) {
  return requestClient.delete<boolean>(`/sys/role/deleteBatchByIds/${ids}`);
}

/**
 * 根据角色ID查询权限
 * @param params 角色ID
 */
export async function queryAuthByRoleIdApi(
  params: SysRoleTableApi.RoleAuthParams,
) {
  return requestClient.get('/sys/rolePermission/queryAuthByRoleId', { params });
}

/**
 * 角色授权
 * @param params
 */
export async function authRoleApi(params: SysRoleTableApi.RoleAuthParams) {
  return requestClient.post(`/sys/rolePermission/authRole`, params);
}
